package com.linchaoen.elema.utils;

public class JsonData {

    private Integer code;

    private String msg;

    private Object data;

    public JsonData() {
    }

    public JsonData(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 成功不返回数据
     *
     * @return
     */
    public static JsonData buildSuccess() {
        return new JsonData(0, null, null);
    }

    /**
     * 成功并返回数据
     *
     * @param data
     * @return
     */
    public static JsonData buildSuccess(Object data) {
        return new JsonData(0, null, data);
    }

    /**
     * 失败返回信息
     *
     * @return
     */
    public static JsonData buildError(String msg) {
        return new JsonData(-1, msg, null);
    }

    /**
     * 失败返回信息, 并自定义状态码
     *
     * @return
     */
    public static JsonData buildError(Integer code, String msg) {
        return new JsonData(code, msg, null);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
